﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace BookStore.Users
{
    public class UseFunctionModule :
        CrudAppService<
            User,
            UserDto,
            int,
            CreateUpdateUserDto>,
        IUseFunctionModule
    {
        private IRepository<User, int> _repository;
        public UseFunctionModule(IRepository<User, int> repository)
            : base(repository) 
        {
            _repository = repository;
        }
        [HttpPost("api/app/user/UseLogin")]
        public async Task<int> UseLogin(string UseName, string UsePword)
        {
            //throw new NotImplementedException();
            //.WhereIf<User>(true, x => x.UseName.Equals(UseName))&& x.UsePword.Equals(UsePword)).Count();
            var log = await _repository.ToListAsync();
            log.Where(x => x.UseName == UseName && x.UsePword == UsePword);
            var login = log.Where(x => x.UseName == UseName && x.UsePword == UsePword).Count();
            return login;
        }
        [HttpGet("api/app/user/CreateAsync")]
        public /*override*/ Task<UserDto> CreateAsync(CreateUpdateUserDto input)
        {
            throw new NotImplementedException();
            /*UserDto u = JsonConvert.DeserializeObject<UserDto>(JsonConvert.SerializeObject(input));
            return base.CreateAsync(u);*/
        }
        [HttpGet("api/app/user/GetListAsync")]
        public Task<PagedResultDto<UserDto>> GetListAsync(PagedAndSortedResultRequestDto input)
        {
            CreateUpdateUserDto c = JsonConvert.DeserializeObject<CreateUpdateUserDto>(JsonConvert.SerializeObject(input));
            return base.GetListAsync(c);
            //throw new NotImplementedException();
        }
        [HttpPost("api/app/user/UpdateAsync")]
        public Task<UserDto> UpdateAsync(int id, CreateUpdateUserDto input)
        {
            throw new NotImplementedException();
        }
    }
}
